package org.zhouhe.modules.website;

import java.util.LinkedHashSet;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.zhouhe.base.BaseAction;
import org.zhouhe.modules.industry.service.IndustryService;
import org.zhouhe.modules.report.service.ReportService;
import org.zhouhe.page.PageUtil;
import org.zhouhe.vo.Industry;
import org.zhouhe.vo.Report;
import org.zhouhe.vo.ReportType;

public class ReportAction extends BaseAction {

	private static final long serialVersionUID = 896164905733014622L;
	private PageUtil pageUtil = new PageUtil();
	private Report report = new Report();
	private String k;//关键字
	private Integer i;//行业ID
	private Integer t;//类型ID
	private Industry paramIndustry = new Industry();
	private ReportType reportType = new ReportType();
	private String pageTitle;
	private List<Industry> industryList;
	private List<ReportType> reportTypeList;
	@Autowired
	private ReportService reportService;
	@Autowired
	private IndustryService industryService;

	public String list() {

		return "list";
	}
	public String freeReportList(){
		this.setPageTitle("免费报告");
		report.setFree(1);//查询条件
		pageUtil = reportService.getReportList(pageUtil, report, getParamIndustry().getIndustryId(), reportType.getReportTypeId());
		return "freeReportList";
	}
	public String search(){
		report.setTitle(k);
		reportService.getReportList(pageUtil, report, i, t);
		if(k != null){
			reportService.updateKeywordHits(k.trim());
		}
		return "search";
	}
	public String detail() {
		report = reportService.getReportDetail(report.getReportId());
		this.setPageTitle(report.getTitle() +" - "+ report.getReportType().getName());
		if(report.getReportType().getReportType() != null){
			this.setPageTitle(this.getPageTitle() +" - "+ report.getReportType().getReportType().getName());
		}
		return "detail";
	}

	/**
	 * 根据报告类型、一级行业显示报告
	 * 
	 * @return
	 */
	public String reportBlocks4txi1() {
		reportType = reportService.getReportType(reportType.getReportTypeId());
		setParamIndustry(reportService.getReport4Industry1(reportType.getReportTypeId(), getParamIndustry().getIndustryId(), 10));
		return "reportBlocks4txi1";
	}

	/**
	 * 根据报告类型、二级行业显示报告
	 * 
	 * @return
	 */
	public String reportList4txix() {
		reportType = reportService.getReportType(reportType.getReportTypeId());
		if(getParamIndustry() != null && getParamIndustry().getIndustryId() != null){
			setParamIndustry(industryService.getIndustryById(getParamIndustry().getIndustryId()));
		}
		pageUtil = reportService.getReportList(pageUtil, report, getParamIndustry().getIndustryId(), reportType.getReportTypeId());
		this.setPageTitle(reportType.getName());
		if(reportType.getReportType() != null){
			this.setPageTitle(this.getPageTitle() +" - "+ reportType.getReportType().getName());
		}
		return "reportList4txix";
	}

	public String reportBlocks4ix(){
		reportTypeList = reportService.getReportTypeList();
		for(ReportType rt : reportTypeList){
			List<Report> reportList = reportService.getReportByType(rt.getReportTypeId(), getParamIndustry().getIndustryId(), 12, false);
			rt.setReports(new LinkedHashSet<Report>(reportList));
		}
		return "reportBlocks4ix";
	}
	public String reportBlocks4t1(){
		reportType = reportService.getReportType(reportType.getReportTypeId());
		for(ReportType rt : reportType.getReportTypes()){
			List<Report> reportList = reportService.getReportByType(rt.getReportTypeId(), getParamIndustry().getIndustryId(), 12, false);
			rt.setReports(new LinkedHashSet<Report>(reportList));
		}
		return "reportBlocks4t1";
	}

	public void setPageUtil(PageUtil pageUtil) {
		this.pageUtil = pageUtil;
	}

	public PageUtil getPageUtil() {
		return pageUtil;
	}

	public void setPageTitle(String pageTitle) {
		this.pageTitle = pageTitle;
	}

	public String getPageTitle() {
		return pageTitle;
	}

	public void setReport(Report report) {
		this.report = report;
	}

	public Report getReport() {
		return report;
	}

	public void setIndustryList(List<Industry> industryList) {
		this.industryList = industryList;
	}

	public List<Industry> getIndustryList() {
		return industryList;
	}

	public void setReportType(ReportType reportType) {
		this.reportType = reportType;
	}

	public ReportType getReportType() {
		return reportType;
	}

	public void setReportTypeList(List<ReportType> reportTypeList) {
		this.reportTypeList = reportTypeList;
	}

	public List<ReportType> getReportTypeList() {
		return reportTypeList;
	}

	public void setParamIndustry(Industry paramIndustry) {
		this.paramIndustry = paramIndustry;
	}

	public Industry getParamIndustry() {
		return paramIndustry;
	}
	public void setK(String k) {
		this.k = k;
	}
	public String getK() {
		return k;
	}
	public void setI(Integer i) {
		this.i = i;
	}
	public Integer getI() {
		return i;
	}
	public void setT(Integer t) {
		this.t = t;
	}
	public Integer getT() {
		return t;
	}
}
